home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / VBASIC / NWT2.ZIP / SERVINFO.FRM (.txt) < prev   
Encoding:
Visual Basic Form  |  1993-08-10  |  10.1 KB  |  292 lines

  1. VERSION 2.00
  2. Begin Form ServerInfoForm 
  3.    Caption         =   "User Information"
  4.    ClientHeight    =   4335
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1485
  7.    ClientWidth     =   6390
  8.    Height          =   4740
  9.    Left            =   1035
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   4335
  12.    ScaleWidth      =   6390
  13.    Top             =   1140
  14.    Width           =   6510
  15.    Begin CommandButton DoneButton 
  16.       Caption         =   "&Done"
  17.       Default         =   -1  'True
  18.       Height          =   375
  19.       Left            =   5400
  20.       TabIndex        =   6
  21.       Top             =   120
  22.       Width           =   855
  23.    End
  24.    Begin ListBox GroupList 
  25.       Height          =   1200
  26.       Left            =   360
  27.       TabIndex        =   1
  28.       Top             =   2520
  29.       Width           =   4935
  30.    End
  31.    Begin ListBox TrusteePathList 
  32.       FontBold        =   -1  'True
  33.       FontItalic      =   0   'False
  34.       FontName        =   "Courier New"
  35.       FontSize        =   9.75
  36.       FontStrikethru  =   0   'False
  37.       FontUnderline   =   0   'False
  38.       Height          =   1230
  39.       Left            =   360
  40.       TabIndex        =   0
  41.       Top             =   720
  42.       Width           =   4935
  43.    End
  44.    Begin Label DriveLabel 
  45.       Height          =   255
  46.       Left            =   360
  47.       TabIndex        =   7
  48.       Top             =   3960
  49.       Width           =   5055
  50.    End
  51.    Begin Label Label3 
  52.       Caption         =   "Group membership:"
  53.       Height          =   255
  54.       Left            =   120
  55.       TabIndex        =   5
  56.       Top             =   2280
  57.       Width           =   1695
  58.    End
  59.    Begin Label VolumeLabel 
  60.       Height          =   255
  61.       Left            =   120
  62.       TabIndex        =   4
  63.       Top             =   480
  64.       Width           =   4575
  65.    End
  66.    Begin Label UserNameLabel 
  67.       Height          =   255
  68.       Left            =   840
  69.       TabIndex        =   3
  70.       Top             =   120
  71.       Width           =   3375
  72.    End
  73.    Begin Label Label1 
  74.       Caption         =   "User:"
  75.       Height          =   255
  76.       Left            =   120
  77.       TabIndex        =   2
  78.       Top             =   120
  79.       Width           =   495
  80.    End
  81. Function AttachToServer (serverName$, userName$, password$) As Integer
  82. 'returns connection ID of specified server if already logged in
  83. 'logs in and returns connection ID, if not already logged in
  84. 'returns 0 if unable to log in
  85. 'password and username can be empty if already logged in to
  86. '   specified server
  87.     Dim loginTime As DATE_AND_TIME
  88.     cCode% = GetConnectionID(serverName$, connectionID%)
  89.     If (cCode% <> SUCCESSFUL) Then
  90.         'either we're not attached, or we're already attached
  91.         If (connectionID% = 0) Then
  92.             'we're not attached
  93.             alreadyAttached% = False
  94.             'Get an attachment to server
  95.             cCode% = AttachToFileServer(serverName$, connectionID%)
  96.             If (cCode% <> SUCCESSFUL) Then
  97.                 AttachToServer = 0
  98.                 Exit Function
  99.             End If
  100.         End If
  101.     End If
  102.     'see if we're logged in, or just attached
  103.     SetPreferredConnectionID (connectionID%)
  104.     connNum& = GetConnectionNumber()
  105.     oName$ = String$(48, 0)
  106.     cCode% = GetConnectionInformation(connNum&, oName$, oType%, oID&, loginTime)
  107.     If (cCode% = SUCCESSFUL) Then
  108.         'we're logged in
  109.         AttachToServer = connectionID%
  110.         alreadyAttached% = True
  111.     Else
  112.         'then log in
  113.         cCode% = LoginToFileServer(userName$, OT_USER, password$)
  114.         If (cCode% <> SUCCESSFUL) Then
  115.             AttachToServer = 0
  116.         Else
  117.             AttachToServer = connectionID%
  118.         End If
  119.         alreadyAttached% = False
  120.     End If
  121. End Function
  122. Function DisconnectFromServer (connectionID%) As Integer
  123.     cCode% = DetachFromFileServer(connectionID%)
  124.     If (cCode% = SUCCESSFUL) Then
  125.         DisconnectFromServer = True
  126.     Else
  127.         DisconnectFromServer = False
  128.     End If
  129. End Function
  130. Sub DoneButton_Click ()
  131.     End
  132. End Sub
  133. Sub Form_Load ()
  134.     'we are assuming that the user has the same username on the default server
  135.     '  and on the server we are attaching to
  136.     connectionID% = AttachToServer(serverName$, userName$, password$)
  137.     If (connectionID% = 0) Then
  138.         MsgBox "Unable to attach to server " + serverName$, MB_OK, "Error"
  139.     Else
  140.         If (MapDriveLetter(connectionID%) <> True) Then
  141.             MsgBox "Unable to map network drive", MB_OK, "Error"
  142.         Else
  143.             DriveLabel.Caption = "Successfully mapped drive to " + serverName$ + "/" + netPath$
  144.         End If
  145.         If (GetTrusteeInformation() <> True) Then
  146.             MsgBox "Error getting trustee information", MB_OK, "Error"
  147.         End If
  148.         If (GetGroupInformation() <> True) Then
  149.             MsgBox "Error getting group  information", MB_OK, "Error"
  150.         End If
  151.         If (Not alreadyAttached%) Then
  152.             If (DisconnectFromServer(connectionID%) <> True) Then
  153.                 MsgBox "Error disconnecting from server " + serverName$, MB_OK, "Error"
  154.             End If
  155.         End If
  156.     End If
  157.     'restore preferred connection ID
  158.     SetPreferredConnectionID (originalPreferredServer%)
  159. End Sub
  160. Function GetGroupInformation () As Integer
  161.     Dim loginTime As DATE_AND_TIME
  162.     Dim seg As PROPERTY_VALUE
  163.     'we already called GetConnectionNumber and GetConnectionInformation
  164.     '  to get the bindery object information in GetTrusteeInformation,
  165.     '  but we'll do it again here, just to keep the two procedures
  166.     '  independent of each other
  167.     connectionNumber& = GetConnectionNumber()
  168.     userName$ = String$(48, 0)
  169.     cCode% = GetConnectionInformation(connectionNumber&, userName$, objectType%, objectID&, loginTime)
  170.     If (cCode% <> SUCCESSFUL) Then
  171.         GetGroupInformation = False
  172.     Else
  173.         segNum% = 1
  174.         Do
  175.             cCode% = ReadPropertyValue(userName$, objectType%, "GROUPS_I'M_IN", segNum%, seg, moreSegs%, flags%)
  176.             i% = 0
  177.             Do
  178.                 'the segment returned by ReadProperty value is an array of up to
  179.                 '  32 longs, each the bindery object ID of a group
  180.                 objectID& = LongSwap(seg.propertyValue(i%))
  181.                 If (objectID& <> 0) Then
  182.                     objectName$ = String$(48, 0)
  183.                     cCode2% = GetBinderyObjectName(objectID&, objectName$, objectType%)
  184.                     If (cCode2% = NO_SUCH_OBJECT) Then
  185.                         GroupList.AddItem "UNKNOWN"
  186.                     ElseIf (cCode2% = SUCCESSFUL) Then
  187.                         GroupList.AddItem objectName$
  188.                     Else
  189.                         MsgBox "Error getting name of group", MB_OK, "Error"
  190.                     End If
  191.                     i% = i% + 1
  192.                 End If
  193.             Loop While ((objectID& <> 0) And (i% < 128))
  194.             segment% = segment% + 1
  195.         Loop While ((cCode% = SUCCESSFUL) And (moreSegs% = 255))
  196.         If (moreSegs% = 255) Then
  197.             GetGroupInformation = False
  198.         Else
  199.             GetGroupInformation = True
  200.         End If
  201.     End If
  202. End Function
  203. Function GetRights (rightsMask%) As String
  204. 'Returns a string corresponding to the trustee rights for
  205. '   the specified rights mask.  Assumes NetWare v3.x/4.x
  206. '   See NWDIR.BAS for global const declarations for
  207. '   NetWare v2. x rights
  208.     If (rightsMask% And TR_READ) Then
  209.         rights$ = "R"
  210.     Else
  211.         rights$ = " "
  212.     End If
  213.     If (rightsMask% And TR_WRITE) Then
  214.         rights$ = rights$ + "W"
  215.     Else
  216.         rights$ = rights$ + " "
  217.     End If
  218.     If (rightsMask% And TR_CREATE) Then
  219.         rights$ = rights$ + "C"
  220.     Else
  221.         rights$ = rights$ + " "
  222.     End If
  223.     If (rightsMask% And TR_ERASE) Then
  224.         rights$ = rights$ + "E"
  225.     Else
  226.         rights$ = rights$ + " "
  227.     End If
  228.     'access control
  229.     If (rightsMask% And TR_ACCESS) Then
  230.         rights$ = rights$ + "A"
  231.     Else
  232.         rights$ = rights$ + " "
  233.     End If
  234.     'file scan
  235.     If (rightsMask% And TR_FILE) Then
  236.         rights$ = rights$ + "F"
  237.     Else
  238.         rights$ = rights$ + " "
  239.     End If
  240.     'modify file attributes
  241.     If (rightsMask% And TR_MODIFY) Then
  242.         rights$ = rights$ + "M"
  243.     Else
  244.         rights$ = rights$ + " "
  245.     End If
  246.     If (rightsMask% And TR_SUPERVISOR) Then
  247.         rights$ = rights$ + "S"
  248.     Else
  249.         rights$ = rights$ + " "
  250.     End If
  251.     GetRights = rights$
  252. End Function
  253. Function GetTrusteeInformation () As Integer
  254.     Dim loginTime As DATE_AND_TIME
  255.     connectionNumber& = GetConnectionNumber()
  256.     userName$ = String$(48, 0)
  257.     cCode% = GetConnectionInformation(connectionNumber&, userName$, objectType%, objectID&, loginTime)
  258.     If (cCode% <> SUCCESSFUL) Then
  259.         GetTrusteeInformation = False
  260.     Else
  261.         volume% = 0
  262.         volumeName$ = String$(16, 0)
  263.         cCode% = GetVolumeName(0, volumeName$)
  264.         VolumeLabel.Caption = "Trustee rights for volume " + volumeName$ + ":"
  265.         sequence% = 0
  266.         Do
  267.             trusteePath$ = String$(255, 0)
  268.             cCode% = ScanBinderyObjectTrusteePaths(objectID&, volume%, sequence%, accessMask%, trusteePath$)
  269.             If ((cCode% = SUCCESSFUL) And (Asc(trusteePath$) <> 0)) Then
  270.                 rights$ = GetRights(accessMask%)
  271.                 TrusteePathList.AddItem rights$ + "  " + trusteePath$
  272.             End If
  273.         Loop While ((cCode% = SUCCESSFUL) And (Asc(trusteePath$) <> 0))
  274.         If (cCode% <> SUCCESSFUL) Then
  275.             GetTrusteeInformation = False
  276.         Else
  277.             GetTrusteeInformation = True
  278.         End If
  279.     End If
  280. End Function
  281. Function MapDriveLetter (connectionID%) As Integer
  282.     'pass a null in driveLetter$ to map next available drive
  283.     driveLetter$ = Chr$(0)
  284.     netPath$ = "SYS:\"
  285.     cCode% = MapDrive(connectionID%, NO_BASE_DRIVE, netPath$, DRIVE_ADD, 0, driveLetter$)
  286.     If (cCode% = SUCCESSFUL) Then
  287.         MapDriveLetter = True
  288.     Else
  289.         MapDriveLetter = False
  290.     End If
  291. End Function
  292.